package com.lwq.logtrace.logback;

import ch.qos.logback.classic.pattern.ClassicConverter;
import ch.qos.logback.classic.spi.ILoggingEvent;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import com.lwq.logtrace.tookit.LogTraceContextHolder;

/**
 * @author 刘文强
 * 扩展对logback的日志链路生成
 */
public class LogTraceConvert extends ClassicConverter {

    @Override
    public String convert(ILoggingEvent iLoggingEvent) {
        String traceId = LogTraceContextHolder.get();
        if (StrUtil.isBlank(traceId)){
            traceId = IdUtil.simpleUUID();
        }
        return traceId;
    }
}
